package orm;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class DBHelper extends SQLiteOpenHelper {
	
	private static final String TABLE_NAME_ENTRIES = "person";
	
	private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ";// + TABLE_NAME_ENTRIES;
	
    // If you change the database schema, you must increment the database version.
    public static final int DATABASE_VERSION = 30;
    public static final String DATABASE_NAME = "intelliFit.db";

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DBContract.Person.CREATE_TABLE_PERSON);
        db.execSQL(DBContract.FitnessData.CREATE_TABLE_FITNESS_DATA);
        db.execSQL(DBContract.ExerciseName.CREATE_TABLE_EXERCISENAME);
        db.execSQL(DBContract.Exercise.CREATE_TABLE_EXERCISE);
        db.execSQL(DBContract.Set.CREATE_TABLE_UNIT);
    }
        
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
        //db.execSQL(SQL_DELETE_ENTRIES);
    	db.execSQL(SQL_DELETE_ENTRIES + DBContract.Person.TABLE_NAME);
    	db.execSQL(SQL_DELETE_ENTRIES + DBContract.FitnessData.TABLE_NAME);
    	db.execSQL(SQL_DELETE_ENTRIES + DBContract.ExerciseName.TABLE_NAME);
    	db.execSQL(SQL_DELETE_ENTRIES + DBContract.Exercise.TABLE_NAME);
    	db.execSQL(SQL_DELETE_ENTRIES + DBContract.Set.TABLE_NAME);
        onCreate(db);
    }
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }

}